import request from '@/utils/request'
import type { ISpuData, ISpuImage, ISpu1, ISaleAttr, ISpuSaleAttrData, ISpuList, ISkuFormData, ISkuItem } from './types'

enum API {
  HASSPU_URL = '/admin/product/',
  ALLTRADEMARK_URL = '/admin/product/baseTrademark/getTrademarkList',
  // 获取某个spu下的全部商品图片数据
  IMAGE_URL = '/admin/product/spuImageList/',
  SALEATTRLIST_URL = '/admin/product/spuSaleAttrList/',
  BASESALEATTRLIST_URL = '/admin/product/baseSaleAttrList',
  ADDSPU_URL = '/admin/product/saveSpuInfo/',
  UPDATESPU_URL = '/admin/product/updateSpuInfo/',
  ADDSKU_URL = '/admin/product/saveSkuInfo/',
  SKUINFOLIST_URL = '/admin/product/findBySpuId/',
  REMOVESPU_URL = '/admin/product/deleteSpu/'
}

export const reqHasSpu = (page: number, limit: number, cate3Id: number | string) =>
  request.get<any, Common<ISpuData>>(API.HASSPU_URL + `${page}/${limit}?category3Id=${cate3Id}`)
// 获取Spu品牌
export const reqAllTrademark = () => request.get<any, Common<ISpu1[]>>(API.ALLTRADEMARK_URL)
// 获取某个spu下的全部商品图片数据
export const reqSpuImageList = (spuId: number) => request.get<any, Common<ISpuImage[]>>(API.IMAGE_URL + spuId)
// 获取某个spu下的全部商品销售属性
export const reqSaleAttrList = (spuId: number) => request.get<any, Common<ISpuSaleAttrData[]>>(API.SALEATTRLIST_URL + spuId)
// 获取整个商品全部销售属性[颜色 版本 尺码]
export const reqBaseSaleAttrList = () => request.get<any, Common<ISaleAttr[]>>(API.BASESALEATTRLIST_URL)

export const reqAddOrUpdateSpu = (data: ISpuList) => {
  if (data.id) {
    return request.post<any, any>(API.UPDATESPU_URL, data)
  } else {
    return request.post<any, any>(API.ADDSPU_URL, data)
  }
}
// 添加Sku
export const reqAddSku = (data: ISkuFormData) => request.post<any, any>(API.ADDSKU_URL, data)
// 查看sku下的全部商品
export const reqSkuInfoList = (spuId: number) => request.get<any, Common<ISkuItem[]>>(API.SKUINFOLIST_URL + spuId)
// 删除spu
export const reqDeleteSpu = (spuId: number) => request.delete<any, any>(API.REMOVESPU_URL + spuId)
